package com.fan.txl.mock.api.annotation;

import com.fan.txl.mock.api.service.mock.MockService;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * Created by jiajiabao on 17-1-16.
 */

public class MockRspParse {

    public static MockRspData parseAnnotation(Class<? extends MockService> mockServiceClass,String methodName) {
       Method[] methods = mockServiceClass.getDeclaredMethods();
        for (Method method: methods) {
            if (method.getName().equalsIgnoreCase(methodName)){

                Annotation[] annotations= method.getAnnotations();
                for (Annotation annotation: annotations) {
                    if (annotation.annotationType()==MockRsp.class){
                        MockRsp mockRsp= (MockRsp)annotation;
                        boolean isMock=mockRsp.mock();
                        String mockPath=mockRsp.path();
                        return new MockRspData(isMock,mockPath);
                    }else{
                        continue;
                    }
                }

            }
        }
        return null;
    }
}
